package com.xjzd.std.concurrency;

public class ThreadState {

    public static void main1(String[] args) {
        Thread t1 = new Thread(() -> {

        });

        System.out.println(t1.getState());
    }

    public static void main2(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            for (; ; ) ;
        });
        t1.start();
        Thread.sleep(500);
        System.out.println(t1.getState());
    }

    public static void main3(String[] args) throws InterruptedException {
        Object obj = new Object();
        Thread t1 = new Thread(() -> {
            synchronized (obj) {
            }
        });

        synchronized (obj) {
            t1.start();
            Thread.sleep(500);
            System.out.println(t1.getState());
        }
    }

    public static void main4(String[] args) throws InterruptedException {
        Object obj = new Object();
        Thread t1 = new Thread(() -> {
            synchronized (obj) {
                try {
                    obj.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        t1.start();
        Thread.sleep(500);
        System.out.println(t1.getState());
    }

    public static void main5(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        t1.start();
        Thread.sleep(500);
        System.out.println(t1.getState());
    }

    public static void main6(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        t1.start();
        Thread.sleep(500);
        System.out.println(t1.getState());
    }

    public static void main7(String[] args) {
        Thread.yield();
        System.out.println("main...");
    }

    public static void main(String[] args) throws InterruptedException {
        Thread.sleep(500);
    }
}
